<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>tab栏切换.html</title>
    <script src="js/jquery-3.6.3.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            box-sizing: border-box;
            text-decoration: none;
        }

        .clearfix::after {
            content: "";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }

        .container {
            width: 1000px;
            margin: 0 auto;
            cursor: pointer;
            border: 1px solid darkgray;
        }

        .tab {
            margin-top: 100px;
        }

        .tab li {
            float: left;
            width: 100px;
            text-align: center;
            border: 1px solid lightgrey;
        }

        .main {
            display: none;
        }

        .selected {
            display: block;
        }

        .main img {
            display: block;
            width: 1000px;
            height: 562px;
        }
        .active{
            background-color: aquamarine;
        }
    </style>
</head>
<body>
<div class="container">
    <ul class="tab clearfix">
        <li class="active">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="product">
        <div class="main selected">
            <img src="images/1.jpg">
        </div>
        <div class="main">
            <img src="images/2.jpg">
        </div>
        <div class="main">
            <img src="images/3.jpg">
        </div>
        <div class="main">
            <img src="images/4.jpg">
        </div>
    </div>
</div>
</body>
<script>
    $(function (){
        $('.tab>li').mouseenter(function (){
            $(this).addClass('active').siblings('li').removeClass('active')
            let index = $(this).index()
            $('.product>div').eq(index).addClass('selected').siblings('div').removeClass('selected')
        })
    })
</script>
</html>